home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2005 January / My Disc.iso / patch / Zoo Tycoon 2 / zoo2patch.exe / x001_000.z2f / scenario / scripts / challenge / money / halfadmission.lua next >
Encoding:
Text File  |  2004-11-12  |  6.0 KB  |  207 lines

  1. -- halfadmission.lua
  2. -- functions for the grantmoney scenario
  3.  
  4. include "scenario/scripts/ui.lua";
  5. include "scenario/scripts/entity.lua";
  6. include "scenario/scripts/economy.lua";
  7. include "scenario/scripts/misc.lua";
  8.  
  9. function validate()
  10.     BFLOG(SYSTRACE, "halfadmission validate");
  11.     
  12.     if ((donealready == nil) or (donealready ~= "true") and (countTypeDirect("animal") > 0) and (not isActivatedByName("Admission Price Free"))) then
  13.         BFLOG(SYSTRACE, "Giving halfadmission challenge");
  14.         local mgr = queryObject("BFScenarioMgr");
  15.         if (mgr) then
  16.             mgr:BFS_ADDSCENARIO("scenario/goals/challenge/halfadmission.xml");    
  17.         end
  18.                     
  19.         return 1;
  20.     end
  21.     
  22.     return 0;
  23. end
  24.  
  25.  
  26. -- gives you half price admission promotion challenge
  27. -- 8/20 revised implementation
  28. -- Set admissions to free
  29. -- Give the player $2500 in cash (grant)
  30. -- Set timer for 1 month. (not 6)
  31. -- Track the admissions they would have received (either at the previous setting the player had, or if necessary, just choose the middle price)
  32. -- During the 1 month, monitor for sickness... any sick animal, challenge failed immediately.
  33.  
  34. -- On failure:
  35. -- Confiscate the sick animal (e.g. just take it away).  We'll take only one -- don't want to hose them too badly but if there is more than one sick animal, pick the "sickest" 
  36.  
  37. -- On success: 
  38. -- Give player another $2500 cash grant
  39. -- Give player the "lost" admissions
  40.  
  41. function evalhalfadmission(comp)
  42.     
  43.     challenge = getglobalvar("challenge");
  44.     
  45.     if (challenge == "accept") then
  46.         local mgr = queryObject("BFScenarioMgr");    
  47.         if (mgr) then
  48.             mgr:BFS_SHOWRULE("halfadmission");
  49.         end
  50.     
  51.         setchallengeactive();
  52.             
  53.         local mgr = queryObject("BFScenarioMgr");
  54.         if(mgr) then
  55.             BFLOG(SYSNOTE, "Disabling UI");
  56.             local uimgr = queryObject("UIRoot");
  57.             if(uimgr) then
  58.                 -- Determine what their admission price is
  59.                 if(isActivatedByName("Admission Price Cheap")) then
  60.                     BFLOG(SYSNOTE, "Setting Comp.Price to CHEAP");
  61.                     comp.price = 10;
  62.                 elseif(isActivatedByName("Admission Price Moderate")) then
  63.                     BFLOG(SYSNOTE, "Setting Comp.Price to Moderate");
  64.                     comp.price = 20;
  65.                 elseif(isActivatedByName("Admission Price Expensive"))then
  66.                     BFLOG(SYSNOTE, "Setting Comp.Price to Expensive");
  67.                     comp.price = 50
  68.                 else
  69.                     comp.price = 20;
  70.                 end
  71.             
  72.                 -- Set the Admission price
  73.                 local freeButton = uimgr:UI_GET_CHILD("Admission Price Free");
  74.                 if(freeButton) then
  75.                     freeButton:UI_ACTIVATE_ON();
  76.                 end
  77.                 disableAdmissions();
  78.             end
  79.             uiDisabled = 1;
  80.         end    
  81.         
  82.         -- Give the cash grant
  83.         giveCash(2500);
  84.         
  85.         -- Set the timers to tick off 1 month
  86.         comp.endMonth = getCurrentMonth() + 1;
  87.         comp.endTimeOfDay = getCurrentTimeOfDay();
  88.         
  89.         -- Get the starting guest count, we need to use lifetime so we can use time of day resolution
  90.         comp.startGuests = getNumGuests(-1);
  91.         BFLOG(SYSNOTE, "Starting Guests: "..comp.startGuests);
  92.         
  93.         comp.accept = 1;
  94.         
  95.     elseif (challenge == "decline") then
  96.         BFLOG(SYSTRACE, "You declined!");
  97.         
  98.         declinenotfail = 1;
  99.                 
  100.         return -1;
  101.     end
  102.     
  103.     if (comp.accept == nil) then
  104.         if (challenge == nil) then
  105.             local showchallengepanel = showchallengepanel("Challengetext:CHgrantmoney");
  106.             BFLOG(SYSTRACE, "I'm waiting for you to click accept or decline!");
  107.             setglobalvar("challenge", "waiting");
  108.         end    
  109.     end
  110.     
  111.     if (comp.accept == 1) then
  112.         -- Do a redundant check to make sure that if they save/load they can't reset admission prices
  113.         if(uiDisabled == nil) then
  114.             local uimgr = queryObject("UIRoot");
  115.             if(uimgr) then
  116.                 -- Set the Admission price
  117.                 local freeButton = uimgr:UI_GET_CHILD("Admission Price Free");
  118.                 if(freeButton) then
  119.                     freeButton:UI_ACTIVATE_ON();
  120.                 end
  121.                 disableAdmissions();
  122.             end
  123.             uiDisabled = 1;
  124.         end
  125.     
  126.         -- Monitor the zoo for animal sickness
  127.         local entity = getSickestAnimal();
  128.         if(entity)then
  129.             -- We found a sick entity, this is a challenge failure
  130.             BFLOG(SYSNOTE, "Found a sick animal, you fail!");
  131.  
  132.             local thetype = entity:BFG_GET_BINDER_TYPE();
  133.             
  134.             -- Remove the _Adult_X from the string
  135.             thetype = getSpeciesFromType(thetype);
  136.             BFLOG(SYSNOTE, "Animal Type: "..thetype);
  137.             
  138.             replacement = getlocidfromspecies(thetype);
  139.  
  140.             -- Take away the sick animal
  141.             deleteEntity(entity);
  142.             enableAdmissions(comp.price);         
  143.             return -1;
  144.         end
  145.         
  146.         --[[ Check to make sure they didn't get rid of their animal or crate it
  147.         if(countTypeDirect("animal") == 0)then
  148.             BFLOG(SYSNOTE, "No Animals Detected!");
  149.             enableAdmissions();
  150.             return -1;
  151.         end --]]
  152.         
  153.         -- Check Timers
  154.         local month = getCurrentMonth();
  155.         local timeOfDay = getCurrentTimeOfDay();
  156.         
  157.         if((month >= comp.endMonth) and (timeOfDay >= comp.endTimeOfDay))then
  158.             --Time is up and no animals were sick so they win
  159.             local admissionCount = getNumGuests(-1) - comp.startGuests;
  160.             
  161.             -- Multiply the admissionCount by the price that they had selected
  162.             gCashReward = 2500 + admissionCount * comp.price
  163.             enableAdmissions(comp.price);
  164.             return 1
  165.         end
  166.     
  167.     end
  168.     
  169.     BFLOG(SYSTRACE, "evalhalfadmission");
  170.     
  171.     return 0;
  172. end
  173.  
  174. function completehalfadmission(comp)
  175.  
  176.     BFLOG(SYSTRACE, "WE DID IT");
  177.     
  178.     showchallengewin("Challengetext:CHgrantmoneySuccess");
  179.     
  180.     resetchallengeoverandcomplete("animalawarenessday");
  181.     
  182.     incrementglobalchallenges();
  183.     
  184.     giveCash(gCashReward);
  185.  
  186.     return 1;
  187. end
  188.  
  189. function failhalfadmission(comp)
  190.     if ((declinenotfail == nil) or (declinenotfail ~= 1)) then
  191.         BFLOG(SYSNOTE, "Failed...popping up the challengefail window");
  192.             
  193.         local stringdat = getLocID("Challengetext:CHgrantmoneyFailureShort");
  194.         local showme = string.format(stringdat, replacement);
  195.         setalttext("halfadmission", "failure", showme);
  196.         
  197.         stringdat = getLocID("Challengetext:CHgrantmoneyFailure");
  198.         showme = string.format(stringdat, replacement);
  199.         setaltoverviewtext("halfadmission", "failure", showme);
  200.     
  201.         showchallengefailtext(showme);
  202.     end
  203.     
  204.     declinenotfail = nil
  205.     resetchallengeover("halfadmission");
  206.     return -1;
  207. end